package com.fwx.system.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class BCryptUtils {
    //加密
    public static String encryptPassword(String password) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        /*加盐加密*/
        return passwordEncoder.encode(password);
    }
    //判断密码是否相同
    //根据数据库查出的加密后的密码，提取当时加密用的盐值
    public static boolean matchesPassword(String rawPassword,String encodePassword) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        return passwordEncoder.matches(rawPassword,encodePassword);
    }

    public static void main(String[] args) {
        System.out.println(encryptPassword("123456"));

        System.out.println(matchesPassword("123456","$2a$10$c0bjr/wkCJrKzKmy5xm3GuL9clIWJiuJh.KciITxAxofNVVYPZEMO"));
    }
}
